import $axios from "@/common/http.js";//请求实例
import { Message } from "element-ui";
import router from "@/router"

/**
 * 活动列表
 * @returns 
 */
export const getBannerlist = async () => {
    return await $axios.get('/bannerlist')
}

/**
 *  添加活动列表
 * @param {*} data 
 * @returns 
 */
export const addBanner = async (data) => {
    let rst = await $axios.post('/banneradd', data)
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,
            onClose() {//关闭之后，回到页面
                router.go(-1);
            }
        })
    }
}

/**
 *  获取一条数据
 * @param {*} id 
 * @returns 
 */
export const editBannerinof = async (id) => {
    let rst = await $axios.get('/bannerinfo', { params: { id } })
    // console.log(rst);
    return rst.list[0]
}


/**
 * 修改
 * @param {*} data 
 */
export const Banneredit = async (data) => {
    let rst = await $axios.post('/banneredit', data)
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,
            onClose() {//关闭之后，回到页面
                router.go(-1);
            }
        })
    }
}

/**
 * 删除
 * @param {*} id 
 * @returns 
 */
export const delBanner = async (id) => {
    let rst = await $axios.post('/bannerdelete', { id })
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,
        })
        return true
    } else {
        return false
    }

}


